// merchant//merchants/jiuCardRecords/index.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    CurrentPage: 1,
    loadingMoreHidden: 1,
    cardItemId: 0,
    cardRecordsList: []
  },
  getRecords: function (cardItemId) {
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/coupon/GetPackageCheckList?uid=' + app.globalData.userInfo.Uid + '&carditemid=' + cardItemId + '&page=' + that.data.CurrentPage,
      success: function (res) {
        if (res.data.Code == 0) {
          let cardRecordsList = res.data.Data.Items;
          if (that.data.CurrentPage != 1) {
            var preGoods = that.data.cardRecordsList
            cardRecordsList = preGoods.concat(cardRecordsList);
          }
          for (let i = 0; i < cardRecordsList.length; i++) {
            cardRecordsList[i].CostMoney = parseFloat(cardRecordsList[i].PayMoney + cardRecordsList[i].CheckMoney).toFixed(2);
            // cardRecordsList[i].AddTime = cardRecordsList[i].AddTime.substr(0, 10);
          }
          that.setData({
            cardRecordsList: cardRecordsList,
            loadingMoreHidden: res.data.Data.TotalPages
          })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options) {
      this.data.cardItemId = options.cardItemId;
      this.getRecords(options.cardItemId);
    }
  },

  loadMore: function () {
    var that = this;
    if (that.data.loadingMoreHidden > 1 && that.data.CurrentPage < that.data.loadingMoreHidden) {
      var currPage = that.data.CurrentPage;
      that.setData({
        CurrentPage: currPage + 1
      })
      that.getRecords(that.data.cardItemId);
    } else {
      return
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})